package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.vo.CategoryVo;
import com.spzx.product.domain.Category;
import com.spzx.product.service.ICategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "商品分类")
@RestController
@RequestMapping("/category")
public class CategoryController extends BaseController {
    @Autowired
    ICategoryService categoryService;

    /**
     * 获取分类下拉树列表
     *
     * @return
     */
    @Operation(summary = "获取分类下拉树列表")
    @GetMapping("/treeSelect/{id}")
    public AjaxResult categoryList(@PathVariable Long id) {
        List<Category> categoryList = categoryService.treeSelect(id);
        return success(categoryList);
    }


    //======================前端调用方法=========================

    /**
     * 首页一级分类集合
     *
     * @return
     */
    @InnerAuth //标识内部调用接口
    @GetMapping("/getOneCategory")
    public R<List<CategoryVo>> getOneCategory() {
        return R.ok(categoryService.getOneCategory());
    }

    /**
     * 分类页的树结构
     *
     * @return
     */
    @InnerAuth //标识内部调用接口
    @GetMapping("/tree")
    public R<List<CategoryVo>> tree() {
        return R.ok(categoryService.tree());
    }

}
